/**
 * @ author: 汪孟苹
 */
define(["jquery","bbcare",
    "scprit/followup/app/datatable/datatable.servers.js",
    "scprit/followup/app/datatable/datatable.ui.js",],function($,$bb,$datatableServers,$datatableUi){
	var servers = {};
	var URL = $bb.baseUrl("followup");
    
    /**
     * 入参
     */
    var inParams = function(args){
        var data = JSON.stringify({
            data: {
                "args": JSON.stringify(args),
                "patientName": $.trim($('#searchByName').val()),
                "hisNo": $.trim($('#searchByHisNo').val()),
                "phoneNum": $.trim($('#searchByPhone').val()),
                "appActFlag":$("#appActFlag").val()
            }
        });
        return data;
    }
    /**
     * 出参
     */
    var outParams = function(data){
        return data.rows;
    }
    /**
     * columns
     */
    var columnsOnlineCompleteNum = function(e){
        return "-";
    }
    var columnsOnlineLostNum = function(e){
        return "-";
    }
    var columnsHisNo = function(e){
        return e.hisNo1 ? e.hisNo1 : e.hisNo2 ? e.hisNo2 : e.hisNo3 ? e.hisNo3 : "-";
    }
    var columnsAppActFlag = function(e){
        return e.appActFlag == "1" ? "已激活" : "未激活";
    }
    var columnsData = function(){
        var columnsArr = [
            {"data":columnsHisNo},
            {"data":'patientName'},
            {"data":'completeNum'},
            {"data":'lostNum'},
            {"data":columnsOnlineCompleteNum},
            {"data":columnsOnlineLostNum},
            {"data":'phoneNum'},
            {"data":'followQueueName'},
            {
                "data":columnsAppActFlag,
                "className":"appActFlag"
            }
        ];
        return columnsArr;
    }
    /**
     * 初始化完成之后的回调函数
     */
    var initComplete = function(setting,json){
        $("#dataCenter").prev("div.row").remove();
        $("#searchByName, #searchByHisNo, #searchByPhone").bind("input propertychange",function(){
            $datatableUi.table.api().ajax.reload();  // 出发dt的重新加载数据的方法
            var args = $datatableUi.table.api().ajax.params();   //获取dt请求参数
        });
        $("#appActFlag").change(function(){
            $datatableUi.table.api().ajax.reload();  // 出发dt的重新加载数据的方法
            var args = $datatableUi.table.api().ajax.params();   //获取dt请求参数
        });
    }
    /**
     * 获取datatable里的options
     */
    servers.getOptions = function(){
        var sessionId = $bb.getSessionStorage("sessionId");
        var options = {
            "ajax": {
                "url": URL + "followup/service/patient/patientListDataCenterQuery?sessionId=" + sessionId,
                "data": inParams,
                "dataSrc": outParams
            },
            "columns": columnsData(),
            "initComplete": initComplete,
        };
        return options;
    }

	return servers;
});